//
//  PHAsset+Ex.swift
//  ToBeBigFE
//
//  Created by mingo on 2020/2/15.
//  Copyright © 2020 com.example. All rights reserved.
//

import Foundation
import Photos
import MobileCoreServices

extension PHAsset {
    
    func size() -> Int {
        guard let resource = PHAssetResource.assetResources(for: self).first else {
            return 0
        }
        return resource.value(forKey: "fileSize") as? Int ?? 0
    }
    
    func mimeType() -> String {
        guard let uti = PHAssetResource.assetResources(for: self).first?.uniformTypeIdentifier else {
            return "image/jpeg"
        }
        let mime = UTTypeCopyPreferredTagWithClass(uti as CFString, kUTTagClassMIMEType)!.takeRetainedValue()
        return mime as String
    }
    
}
